package com.qcl.controller;

import com.qcl.api.ResultVO;
import com.qcl.bean.Paihao;
import com.qcl.bean.PictureInfo;
import com.qcl.repository.PaihaoRepository;
import com.qcl.repository.PictureRepository;
import com.qcl.request.PictureForm;
import com.qcl.utils.ApiUtil;
import com.qcl.utils.TimeUtils;
import com.qcl.yichang.DianCanException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.sql.Time;
import java.util.List;

/**
 * 排号相关
 */
@Controller
@RequestMapping("/adminPaihao")
@Slf4j
public class AdminPaihaoController {

    @Autowired
    PaihaoRepository repository;

    //显示所有的排号用户
    @GetMapping("/list")
    public String list(ModelMap map) {
        List<Paihao> listSmall = repository.findByDayAndTypeAndRuzhuoOrderByNum(TimeUtils.getYMD(), 0, false);
        List<Paihao> listBig = repository.findByDayAndTypeAndRuzhuoOrderByNum(TimeUtils.getYMD(), 1, false);
        map.put("listSmall", listSmall);
        map.put("listBig", listBig);
        return "paihao/list";
    }


    //删除轮播图
    @GetMapping("/ruzhuo")
    public String ruzhuo(@RequestParam(value = "id", required = false) Integer id,
                         ModelMap map) {
        Paihao paihao = repository.findById(id).orElse(null);
        paihao.setRuzhuo(true);
        repository.save(paihao);
        map.put("url", "/diancan/adminPaihao/list");
        return "zujian/success";
    }


}
